package com.ossjk.qlh.project.controller;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ossjk.core.base.controller.BaseController;
import com.ossjk.core.vo.ResponseBean;
import com.ossjk.qlh.project.entity.BuildProject;
import com.ossjk.qlh.project.service.IBuildProjectService;
import com.ossjk.qlh.project.vo.ProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * Copyright  2022-01-06 QLH. Tech Ltd. All rights reserved.
 * 
 * @Package: com.ossjk.qlh.project.controller
 * @ClassName: BuildProjectController
 * @Description: -控制器
 * @author: DengJing
 * @date:  2022-01-06 09:26:16 
 */
@Api(tags = "合同表")
@RestController
@RequestMapping("/project/buildProject")
public class BuildProjectController extends BaseController {
	
	@Autowired
	private IBuildProjectService iBuildProjectService;

	@ApiOperation(value = "列表")
	@RequiresPermissions("000000250000")
	@GetMapping("/list")
	public ResponseBean<Page<ProjectVo>> list(Page page, @RequestParam(name ="name", required = false) String val) {
		QueryWrapper<BuildProject> queryWrapper = new QueryWrapper<BuildProject>();
		if(StrUtil.isNotBlank(val)){
			queryWrapper.like("project_name",val);
		}
		return ResponseBean.Success(iBuildProjectService.pageVo(page,queryWrapper));
	}

	@ApiOperation(value = "添加")
	@RequiresPermissions("000000250005")
	@PostMapping("/save")
	public ResponseBean save(@RequestBody BuildProject record) {
		if (iBuildProjectService.save(record)) {
			return ResponseBean.Success();
		} else {
			return ResponseBean.Fail();
		}
	}

	@ApiOperation(value = "去编辑")
	@RequiresPermissions("000000250010")
	@GetMapping("/toUpdate")
	public ResponseBean<BuildProject> toUpdate(@ApiParam(value = "id") @RequestParam(name = "id") String id) {
		BuildProject buildProject = iBuildProjectService.getById(id);
		if (ObjectUtil.isNotNull(buildProject)) {
			return ResponseBean.Success(buildProject);
		} else {
			return ResponseBean.Fail();
		}
	}


	@ApiOperation(value = "编辑")
	@RequiresPermissions("000000250015")
	@PutMapping("/update")
	public ResponseBean update(@RequestBody BuildProject record) {
		if (iBuildProjectService.updateById(record)) {
			return ResponseBean.Success();
		} else {
			return ResponseBean.Fail();
		}
	}

	@ApiOperation(value = "删除")
	@RequiresPermissions("000000250020")
	@DeleteMapping("/remove")
	public ResponseBean remove(@ApiParam(value = "ids") @RequestParam(name = "ids") String[] ids) {
		if (iBuildProjectService.removeByIds(Arrays.asList(ids))) {
			return ResponseBean.Success();
		} else {
			return ResponseBean.Fail();
		}
	}
}
